<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/page/share/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>购物车 52橙子网</title>
<meta http-equiv=Content-Type content="text/html; charset=UTF-8"/>
<meta http-equiv=Content-Language content=zh-CN/>
<link href="/shop/css/new_cart.css" rel="stylesheet" type="text/css" />
<link href="/shop/css/global/header01.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="/shop/css/global/top.css" media="all" type="text/css"/>
<link rel="stylesheet" href="/shop/css/buycart/car.css" media="all" type="text/css"/>
<script language=JavaScript src="/shop/js/FoshanRen.js"></script>
<script language="JavaScript">
<!--
/** 获取以指定字符串为前缀的输入字段集合 **/
/** 数字输入格式是否正确(长度1-4位，第一个数字必须是1-9) **/
function numericFormat(strNumber){   
  var newPar=/^[1-9]\d{0,3}$/;
  return newPar.test(strNumber);
} 

function getInputsByname(name, etype){//
	var inputs = document.getElementsByTagName("input");
	var texts = new Array();
	var y = 0;
	for (var i = 0; i < inputs.length; i++) {
	  if (inputs[i].type == etype && inputs[i].name!=null && inputs[i].name.substring(0, name.length) == name) {
			texts[y] = inputs[i];
			y++;
		}
	}
	return texts;
}
function settleAccounts(){
	if(validateAmount()){		
		var form = document.forms["buycart"];
		form.method.value="settleAccounts";
		form.submit();
	}
}

function modifyAmount(){
	if(validateAmount()){		
		var form = document.forms["buycart"];
		form.method.value="updateAmount";
		form.submit();
	}
}

/** 验证购买数量字段 **/
function validateAmount(){
	var amounts = getInputsByname("amount_", "text");
	if(amounts.length==0){
		alert("您还没有购买商品");
		return false;
	}else{
		for (var i = 0; i < amounts.length; i++) {
			var amount = amounts[i];
			if(amount.value==null || amount.value.trim()==""){
				alert("\n您购买的商品中,有的商品购买数量为空,请填写购买数量");
				amount.focus();
				return false;
			}else if(amount.value=="0"){
				alert("\n您购买的商品中,有的商品购买数量为0,如果您不需要该商品,可以删除它");
				amount.select();
				return false;
			}else if(!numericFormat(amount.value)){
				alert("\n购买数量含有非数字数据,请更正");
				amount.select();
				return false;
			}
		}
	}
	return true;
}
//-->
</script>
</head>
<BODY>
<div class="container">
<jsp:include page="/WEB-INF/page/share/Head.jsp"/>
<BR>

<form id="buycart" name="buycart" action="<html:rewrite action='/shopping/cart/manage' />" method="post">
    <input TYPE="hidden" NAME="method" value="" />
     <input TYPE="hidden" NAME="directUrl" value="${param.directUrl}" />
<div class="product">
        	<div class="product_header">
            	<div class="product_header_logo">
                	<div class="product_header_logo_text"><font>如果您修改了产品数量请点击</font></div>
                    <div class="product_header_logo_btn"><img style="CURSOR:hand;" src="/shop/image/cart/renew_btn.png" alt="修改数量" value="修改数量" border="0" onclick="javascript:modifyAmount()"/></div>
                </div>
                <div class="product_header_text"><font><a href="<html:rewrite action="/shopping/cart/manage" />?method=deleteAll&directUrl=${param.directUrl}">清空购物车</a></font></div>
                <div class="product_header_keep"><a href="/shop"><img src="/shop/image/cart/keepon_btn.png" border=0/></a></div>
                <div class="product_header_center"><img src="/shop/image/cart/gocenter_btn.png" style="CURSOR:hand;" onclick="javascript:settleAccounts()"/></div>
            </div>
            
            <div class="product_list_title">
            	<div class="product_list_product"><font style="color:#666666;">我购物车里的商品</font></div>
                <div class="product_list_value"><font style="color:#666666;">市场价</font></div>
                <div class="product_list_rmb"><font style="color:#666666;">价格</font></div>
                <div class="product_list_num"><font style="color:#666666;">数量</font></div>
            </div>
            
        	<div class="product_list_goods">
            <c:forEach items="${buyCart.items}" var="item"> 
            <div class="product_product">
                	<img src=""/><br/>
                    <font class="product_product_font1">${item.product.name}</font><font class="product_product_font2">颜色/样式:<c:forEach items="${item.product.styles}" var="style">${style.name}</c:forEach></font>
            </div>
             <div class="product_value">
                	<font class="product_value_font">￥${item.product.marketprice}元</font>
                </div>
                 <div class="product_rmb">
                	<font class="product_rmb_font1">￥${item.product.marketprice}元</font><br/>
                    <font class="product_rmb_font2">为您节省:</font><font class="product_rmb_font1">￥${item.product.sellprice}元</font>
                </div>
                <div class="product_num">
                	<div class="product_num_input"><input type="text" value="${item.amount}" name="amount_${item.product.id}_<c:forEach items="${item.product.styles}" var="style">${style.id}</c:forEach>" onkeypress="javascript:InputIntNumberCheck()"/></div>
                    <div class="product_num_img"><img src="/shop/image/cart/del_btn.png"/></div>
                </div>
      		</div>
			</c:forEach>
            <div class="product_list_line"></div>
            <div class="product_footer"></div>
        </div><!--end product-->
        </form>
<jsp:include page="/WEB-INF/page/share/Foot.jsp" />
</div><!--end container-->
</BODY>
</HTML>
